package com.timerecording.service.users;

import com.timerecording.domain.entity.UserEntity;
import com.timerecording.domain.vo.login.LoginUserVO;
import com.timerecording.service.login.LoginService;
import com.timerecording.util.ResponseCodeConst;
import com.timerecording.util.ResponseDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author smz41
 * @description: TODO
 * @date 2025/7/25
 */
@Service
public class UserService {



    @Autowired
    private LoginService loginService;

    /**  根据token查询用户信息
     * @description: TODO
     * @author smz
     * @version 1.0
     * @date 2025/7/25
     */

    public ResponseDTO currentUserByToken(String token) {
        /*
        * 1、token合法性校验    是否为空  解析是否成功  redis是否存在
        * 2、如果校验错误，返回错误
        * 3、如果校验成功，返回对应的结果
        */
        UserEntity userEntity = loginService.checkToken(token);
        if (userEntity == null){
            return ResponseDTO.wrapMsg(ResponseCodeConst.TOKEN_NOT_EXIST,"token不合法！");
        }
        LoginUserVO loginUserVO = new LoginUserVO();
        loginUserVO.setUserId(userEntity.getUserId());
        loginUserVO.setLoginName(userEntity.getUserName());
        loginUserVO.setLoginPwd(userEntity.getUserPwd());
        loginUserVO.setAvatar(userEntity.getAvatar());
        return ResponseDTO.succData(loginUserVO);
    }
}
